package com.gui.mapper;

import com.gui.model.Question;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * QuestionMapper
 *
 * @author guigu
 * @QQ 1170258867
 * @date 2020/5/29
 * @description
 */
@Mapper
@Component
public interface QuestionMapper {

    @Insert("insert into QUESTION(title, description, gtm_create,tag,creator) values ( #{title},#{description},#{gtmCreate},#{tag},#{creator})")
    void insertNewPublish(Question question);

    @Select("select * from question")
    List<Question> getAllQuestion();

    @Select("select * from question limit #{prequest},5")
    List<Question> getLimitQuestion(int prequest);

    @Select("select * from question where creator = #{user} limit #{prequest},5")
    List<Question> getLimitQuestionPerson(@Param("prequest") int prequest,@Param("user") int user);

    @Select("select count(1)  from question")
    int getCountquestion();

    @Select("select count(1)  from question where creator = #{creator}")
    int getPersonalCountquestion(int creator);

    @Select("select * from question where id = #{id}")
    Question getOneQuestion(int id);

    @Update("update QUESTION set TITLE = #{title},DESCRIPTION = #{description},TAG = #{tag} where ID = #{id}")
    int updateQuestion(Question question);

}
